﻿using StudentManagement.Entity;
using System;
using System.Data;
using System.Data.SqlClient;

namespace StudentManagement.DAL
{
    public  class AlterStudentInfoData
    {
        public bool AddStudentInfo(StudentInfoEntity studentInfoEntity)
        {
            string addSql = "INSERT INTO UseDto (Name, Account,Password,Sex,Remark) VALUES (@Name, @Account,@Password,@Sex,@Remark) ";
            SqlParameter[] sqlParameter = new SqlParameter[]
            {
                new SqlParameter("@Name",studentInfoEntity.Name),
                new SqlParameter("@Account",studentInfoEntity.Account),
                new SqlParameter("@Password",studentInfoEntity.Password),
                new SqlParameter("@Sex",studentInfoEntity.Sex),
                new SqlParameter("@Remark",studentInfoEntity.Remark)
            };
            int res = SQLHelper.ExecteNonQuery(CommandType.Text, addSql, sqlParameter);
            if (res > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }
        public bool IsExistAccount(string account)
        {
            string queryAccountSql = $"select count(1) from UseDto where Account = '{account}'";
            int res = Convert.ToInt32(SQLHelper.ExecuteScalarText(queryAccountSql));
            if (res >　0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public bool UpdatePwd(StudentInfoEntity studentInfoEntity)
        {
            string addSql = "update UseDto set Password=@Password where Account = @Account";
            SqlParameter[] sqlParameter = new SqlParameter[]
            {
                new SqlParameter("@Account",studentInfoEntity.Account),
                new SqlParameter("@Password",studentInfoEntity.Password) 
            };
            int res = SQLHelper.ExecteNonQuery(CommandType.Text, addSql, sqlParameter);
            if (res > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        
    }
}
